package gof_002_结构型_Structural.gof_001_代理_Proxy.gof_003_DynamicProxy.g_1_jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

public class ProxyClient {
    public static void main(String[] args) {
        /**
         * 活动公司找代理人,代理人去找歌手
         */
        Agent agent = new Agent(new ZhaoLei());

        ClassLoader loader = ClassLoader.getSystemClassLoader();
        Class[] interfaces = {Singer.class, Performer.class};
        InvocationHandler h = agent;
        Singer singer = (Singer) Proxy.newProxyInstance(loader, interfaces, h);
        singer.sing();


        /**
         * 活动公司找代理人,代理人去找演员
         */
        Agent agent2 = new Agent(new LiuDeHua());

        ClassLoader loader2 = ClassLoader.getSystemClassLoader();
        Class[] interfaces2 = {Singer.class,Performer.class};
        InvocationHandler h2 = agent2;
        Performer performer = (Performer) Proxy.newProxyInstance(loader2, interfaces2, h2);
        performer.perform();
    }
}